Lecture 5
The previous figure is taken from data-to-viz.com
Based on the type of variable, different graphical representations are available
Conveying information through plot is an art (data visualization)
Impossible to see everything also in an entire course devoted to data visualization
A picture is worth a thousand words
plot()The simplest (and probably most important) R function for creating a plot is plot().
Its behavior depends on the “class” of the objects passed as input. Let’s create a basic scatter plot.
?plot.default, we see that the function accepts various arguments and graphical parameters to modify and adjust the appearance of a plot.points() function. Here’s how.mfrow parameter.We can use the segments() and lines() functions to add lines and segments to an existing plot.
lwd modifies line widthcol modifies line colorlty modifies line typeThe plot() function is vectorized with respect to its parameters. This means we can pass vectors to certain arguments like color (col), point type (pch), and size (cex).
lines()The lines() function can be used to add lines to an existing plot. It behaves similarly to plot(), allowing you to easily overlay multiple functions.
lines()hist()We can control the number of breakpoints using the breaks argument.
The hist() function can plot relative frequencies, and the density() function can be used to estimate the probability density of the data.
density()The density() function provides a non-parametric estimate of the probability density function.
curve()The curve() function is used to plot mathematical expressions or functions in R. Here’s an example of plotting a cubic function.
The curve() function can also be used to plot predefined functions like dnorm(), which represents the probability density function of a normal distribution.
curve() PlotThe ecdf() function calculates the ECDF for a numeric vector. ECDF represents the percentage of values in x that are less than or equal to t.
barplot()boxplot()